Trouble rotating viewplatform in Java3D [closed]
Posted
by
user29163
on Programmers
See other posts from Programmers
or by user29163
Published on 2012-11-01T09:22:53Z
Indexed on
2012/11/01
11:14 UTC
Read the original article
Hit count: 268
I have just started with Java3D programming. I thought I had built up some basic intuition about how the scene graph works, but something that should work, does not work.
I made a simple program for rotating a pyramid around the y-axis. This was done just by adding a RotationInterpolator
R to the TransformGroup
above the pyramid. Then I thought hey, can I now remove the RotationInterpolator
from this TransformGroup
, then add it to the TransformGroup
above my ViewPlatform
leaf. This should work if I have understood how things work. Adding the RotationInterpolator
to this TransformGroup
, should make the children of this TransformGroup
rotate, and the ViewingPlatform
is a child of the TransformGroup
. Any ideas on where my reasoning is flawed?
Here is the code for setting up the universe, and the view branchgroup.
import java.awt.*;
import java.awt.event.*;
import javax.media.j3d.*;
import javax.vecmath.*;
public class UniverseBuilder {
// User-specified canvas
Canvas3D canvas;
// Scene graph elements to which the user may want access
VirtualUniverse universe;
Locale locale;
TransformGroup vpTrans;
View view;
public UniverseBuilder(Canvas3D c) {
this.canvas = c;
// Establish a virtual universe that has a single
// hi-res Locale
universe = new VirtualUniverse();
locale = new Locale(universe);
// Create a PhysicalBody and PhysicalEnvironment object
PhysicalBody body = new PhysicalBody();
PhysicalEnvironment environment = new PhysicalEnvironment();
// Create a View and attach the Canvas3D and the physical
// body and environment to the view.
view = new View();
view.addCanvas3D(c);
view.setPhysicalBody(body);
view.setPhysicalEnvironment(environment);
// Create a BranchGroup node for the view platform
BranchGroup vpRoot = new BranchGroup();
// Create a ViewPlatform object, and its associated
// TransformGroup object, and attach it to the root of the
// subgraph. Attach the view to the view platform.
Transform3D t = new Transform3D();
Transform3D s = new Transform3D();
t.set(new Vector3f(0.0f, 0.0f, 10.0f));
t.rotX(-Math.PI/4);
s.set(new Vector3f(0.0f, 0.0f, 10.0f)); //forandre verdier her for å endre viewing position
t.mul(s);
ViewPlatform vp = new ViewPlatform();
vpTrans = new TransformGroup(t);
vpTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
// Rotator stuff
Transform3D yAxis = new Transform3D();
//yAxis.rotY(Math.PI/2);
Alpha rotationAlpha = new Alpha(
-1, Alpha.INCREASING_ENABLE,
0, 0,4000, 0, 0, 0, 0, 0);
RotationInterpolator rotator = new RotationInterpolator(
rotationAlpha, vpTrans, yAxis,
0.0f, (float) Math.PI*2.0f);
RotationInterpolator rotator2 = new RotationInterpolator(
rotationAlpha, vpTrans);
BoundingSphere bounds =
new BoundingSphere(new Point3d(0.0,0.0,0.0), 1000.0);
rotator.setSchedulingBounds(bounds);
vpTrans.addChild(rotator);
vpTrans.addChild(vp);
vpRoot.addChild(vpTrans);
view.attachViewPlatform(vp);
// Attach the branch graph to the universe, via the
// Locale. The scene graph is now live!
locale.addBranchGraph(vpRoot);
}
public void addBranchGraph(BranchGroup bg) {
locale.addBranchGraph(bg);
}
}
© Programmers or respective owner